using CommunityToolkit.Maui.Views;
using System.Collections;
using System.ComponentModel.DataAnnotations;

namespace MauiApp1;

public partial class CustomPickeView : Popup
{
    public CustomPickeView(IEnumerable itemSource, DataTemplate? itemTemplate,Action<object>? action , double pickerControlHeight = 200)
    {
        InitializeComponent();
        clPickerView.ItemsSource = itemSource;
        clPickerView.ItemTemplate = itemTemplate;
        clPickerView.HeightRequest = pickerControlHeight;
        Clicked = action;
    }

    public Action<object>? Clicked {  get; set; }

    private void clPickerView_SelectionChanged(object obj, SelectionChangedEventArgs e)
    {
        var currentItem = e.CurrentSelection.FirstOrDefault();
        if (currentItem != null)
        {
          Clicked?.Invoke(currentItem);
        }
        Close(currentItem);
    }
}